﻿using System;
using System.Collections.Generic;
using System.ServiceModel;

using SsrsRenderStudio.Wcf.ServiceContract;
using SsrsRenderStudio.Wcf.DataContract;
using SsrsRenderStudio.Shared;
using SsrsRenderStudio.Configuration;
using SsrsRenderStudio.KnownTypesAndModels;

namespace SsrsRenderStudio.Wcf.ServiceImpl
{
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)]
    public class RenderStudioSystemService: IRenderStudioSystemService
    {
        public int GetServerStatus()
        {
            return 666;
        }

        public ApplicationConfigResponse GetApplicationConfiguration()
        {
            return new ApplicationConfigResponse { ApplicationConfig = new ApplicationConfig10() };
        }

        public SmtpConfigurationResponse GetSmtpConfiguration()
        {
            return new SmtpConfigurationResponse { SmtpConfiguration = new SmtpConfig10() };
        }

        public LoggingConfigurationsResponse GetAllLoggingConfigurations()
        {
            LoggingConfigurationsResponse response =  new LoggingConfigurationsResponse { LoggingConfigurations = new List<LoggingConfig10>() };
            response.LoggingConfigurations.Add(new LoggingConfig10 { Actions = new List<LoggingAction10>(), IsImmediate = true, LoggingVerbosity = 100, LogProcessingInterval = new TimeSpan(0, 0, 30), SourceName = "dummy" });
            response.LoggingConfigurations[0].Actions.Add(new LoggingAction10 { Action = EnumLoggingAction.NONE, Parameters = new ParameterHash(new string[] { "param", "hash" }),  Severity = EnumLoggingSeverity.CRITICAL });
            response.LoggingConfigurations[0].Actions.Add(new LoggingAction10 { Action = EnumLoggingAction.NONE, Parameters = new ParameterHash(new string[] { "param", "hash" }),  Severity = EnumLoggingSeverity.CRITICAL });

            //return new LoggingConfigurationsResponse { LoggingConfigurations = new List<LoggingConfig10>() };

            return response;
        }

        public EndpointConfigurationsResponse GetAllEndpointConfigurations()
        {
            return new EndpointConfigurationsResponse { EndpointConfigurations = new List<EndpointConfig10>() };
        }

        public RenderStudioClientsResponse GetAllRenderStudioClients()
        {
            return new RenderStudioClientsResponse { RenderStudioClientConfigurations = new List<RenderStudioClientConfig10>() };
        }

        public RenderStudioServersResponse GetAllRenderStudioServers()
        {
            return new RenderStudioServersResponse { RenderStudioServerConfigurations = new List<RenderStudioServerConfig10>() };
        }

        public ReportServersResponse GetAllReportServers()
        {
            return new ReportServersResponse { ReportServerConfigurations = new List<ReportServerConfig10>() };
        }

        public ReportsResponse GetAllReports()
        {
            return new ReportsResponse { ReportConfigurations = Configuration.ConfigurationManager.ReportSettingsGetAll10() };
        }

        public PrintersResponse GetAllPrinters()
        {
            return new PrintersResponse { PrinterConfigurations = new List<PrinterInfo10>() };
        }

       

        /*private Dictionary<Guid, ProcessedReport> _processedReports = new Dictionary<Guid, ProcessedReport>();

        public Guid RegisterReportInCache(EnumOutputType outputType, byte[][] renderedBuffer, string destination, string extension, string encodingType)
        {
            Guid g = Guid.NewGuid();

            _processedReports.Add(g, new ProcessedReport(outputType, renderedBuffer, destination, extension, encodingType));

            return g;
        }

        public ProcessedReport GetProcessedReportInfo(Guid id)
        {
            ProcessedReport rpt = null;
            _processedReports.TryGetValue(id, out rpt);
            return rpt;

            
            if (_processedReports.TryGetValue(id, out rpt))
            {
                Output output = null;
                switch (rpt.OutputType)
                {
                    case EnumOutputType.PRINTER:
                        output = new PrinterOutput(rpt.RenderedBuffer, rpt.Destination);
                        break;
                    case EnumOutputType.EMAIL:
                        output = new EmailOutput(rpt.RenderedBuffer, rpt.Destination, rpt.Extension, rpt.EncodingType);
                        break;
                    default:
                        output = new NullOutput();
                        break;
                }

                output.Process();
                output = null;

                return true;
            }
            else
            {
                return false;
            }
            

        }
        */





        
    }

   
}
